<template>
<view>
<view v-if="PaiXuPartials" class="container">
  <block>
    <custom-page-index-component id='container' :receiveData="sendFooterData" v-if="sendFooterData"></custom-page-index-component>
  </block>
</view>   
<view v-else class="blankPage">
   <view class="blankPage_image"></view>
   <text>网络异常，请刷新本页</text>
   <button></button>
</view>
</view>
</template>

<script>
var timer; // 计时器
export default {
  data() {
    return {
      listenerId: null,
      setting: null,
      renderData: null,
      PaiXuPartials: [],
      sysWidth: 750,
      //图片大小
      partialsName: '',
      loginUser: null,
      sendFooterData: null,
      options:null,
    };
  },
  props: {},

  /*onload*/
  onLoad: function (options) {
    console.warn("======onLoad:options======", options);
    this.options=options
    console.log('--------------- custom_index --------------');
    if (!getApp().globalData.setting) {
      getApp().globalData.promiseonLaunch(this);
    } else {
      this.setData({
        sysWidth: getApp().globalData.sysWidth
      });
      let sendFooterData = JSON.stringify({
        title: 'title',
        url: "footer2",
        params: {
          pageObjectId: options.id || ""
        }
      });
      this.setData({
        sendFooterData: sendFooterData
      }); 

      if (!!getApp().globalData.setting) {
        console.log("=====setting=====");
        this.setNavBar();
      }
    }
  },
  onReady: function () {},
  onShow: function () {
    console.log('-----------------a---------------');
    getApp().globalData.addAuthorizationListenerItem(this)
  },
  // /* 分享 app.js862行*/
  // onShareAppMessage: function () {
  //   console.log(app.miniIndexPage)
  //   return app.shareForFx2(app.miniIndexPage)
  // },
  onPullDownRefresh: function () {
    this.refreshPage(this.options)
    wx.stopPullDownRefresh();
  },
  onReachBottom: function () {
    console.log('===onReachBottom====');
    var that = this;
    that.selectComponent("#container").onReachBottom();
  },
  methods: {
    refreshPage: function (options) {
      let that = this;
      console.log("首页刷新");
      that.setNavBar();
      wx.showToast({
        title: '加载中...',
        icon: 'none',
        duration: 500
      });
      that.setData({
        sendFooterData: null
      });
      setTimeout(function () {
        if (!getApp().globalData.setting) {
          getApp().globalData.promiseonLaunch(that);
        } else {
          that.setData({
            sysWidth: getApp().globalData.sysWidth
          });
          let sendFooterData = JSON.stringify({
            title: 'title',
            url: "footer2",
            params: {
              pageObjectId: options.id || ""
            }
          });
          that.setData({
            sendFooterData: sendFooterData
          });
        }
      }, 500);
    },
    getStateData: function (state) {
      let that = this;
      console.log("===getStateData===", state);
      that.selectComponent("#container").setPopupState(state);
    },
    setNavBar: function () {
      console.warn("1111111111111", getApp().globalData.setting.platformSetting);
      wx.setNavigationBarColor({
        frontColor: getApp().globalData.setting.platformSetting.topColor.toLowerCase(),
        backgroundColor: getApp().globalData.setting.platformSetting.topBgColor
      });
    },
    getData: function () {
      console.log('---------------index - getsetting --------------');
      var that = this;

      if (!getApp().globalData.setting) {
        console.log('-------------hasNoneSetting-----------');
        getApp().globalData.getSetting(that);
      } else {
        console.log('-------------hasSetting-----------');
        this.setData({
          setting: getApp().globalData.setting
        });
        console.log(this.setting);
      }
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>